package com.ukao.cashregister.pesenter;

import android.content.Context;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.BaseBean;
import com.ukao.cashregister.bean.ReceiptBean;
import com.ukao.cashregister.bean.StringBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.view.ClothingDetailsView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/26.
 */

public class ClothingDetailsPesenter extends BasePresenter<ClothingDetailsView> {

    public ClothingDetailsPesenter(ClothingDetailsView view) {
        attachView(view);
    }




    /**
     出库
     */
    public void stockOut(Context  mContext,String id) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("id", id);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.stockOut(Constant.createParameter(mHashMap)),
                new ApiCallback<BaseBean>() {
                    @Override
                    public void onSuccess(BaseBean model) {

                        if (model.getHttpCode() == 200) {

                            mvpView.loadSuccess(model.getMsg());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }




                    @Override
                    public void onFinish() {
                    mvpView.hideLoading();
                    }
                });
    }

    /**
     返工
     */
    public void stockRework(Context  mmContext,String id) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("id", id);
        mHashMap.put("accessToken", SaveParamets.getToken(mmContext));
        addSubscription(apiStores.stockRework(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode() == 200) {

                                mvpView.loadSuccess(model.getMsg());

                        }else{
                              mvpView.loadFail(model.getMsg());

                        }
                    }




                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }
                });
    }



    /**
     *打印订单
     */
    public void printReceipt(Context context, String  id ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("orderId",id);
        mHashMap.put("accessToken", SaveParamets.getToken(context));
        addSubscription(apiStores.printReceipt(Constant.createParameter(mHashMap)),
                new ApiCallback<ReceiptBean>() {
                    @Override
                    public void onSuccess(ReceiptBean model) {
                        if (model.getHttpCode()==200){
                            mvpView.loadReceipt(model.getData());
                        }else{
                            mvpView.loadFail(model.getMsg());
                        }


                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }



}
